<?php
include('../adodb5/adodb.inc.php');
$db = ADONewConnection("mysql"); # eg 'mysql' or 'postgres'
//$db->debug = true;
$db->Connect("localhost", "root", "112233", "test");     

if(isset($_GET['id'])){
	$id = addslashes($_GET['id']);
	$rs = $db->Execute("select id,firstname,lastname,age from customer where id=$id");
	$data = $rs->GetRows();
	$firstname = $data[0]['firstname'];
	$lastname = $data[0]['lastname'];
	$age = $data[0]['age'];
	$content = "
	<form action=\"edit.php?id=$id\" method=\"post\">
	Firstname
	<br/>
	<input type=\"text\" name=\"firstname\" value=\"$firstname\">
	<br/>
	Lastname<br/>
	<input type=\"text\" name=\"lastname\" value=\"$lastname\"><br/>
	Age<br/>
	<input type=\"text\" name=\"age\" value=\"$age\"><br/>
	<input type=\"submit\" name=\"submit\" value=\"Simpan\">
	";
	
	if(isset($_POST['submit'])){
		if(!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['age'])){
			$query = "update customer set firstname='".addslashes($_POST['firstname'])."',lastname='".addslashes($_POST['lastname'])."',age='".addslashes($_POST['age'])."' where id=$id";
			$rs = $db->Execute($query);
			
			if($rs === false){
				$content.="<strong>Update gagal</strong> <a href=\"listarray.php\">Kembali ke List Data</a><br/>";
			} else {
				echo "<strong>Update berhasil</strong> <a href=\"listarray.php\">List Data</a>";
			}
		}
	} else {
		echo $content;
	}
} else {
	echo "Tidak ada ID! Kembali ke List Data <a href=\"listarray.php\">List Data</a>";
}
?>